package com.ibatis4J.framework.dal.dao.support.rowmapper;

import java.util.Date;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper;

/**
 * 映射类型工厂
 * 
 * @author liuwenya
 * 
 * @param <T> class 实现类
 */
public class RowMapperFactory<T> {
	
	/**
	 * 需处理的类型
	 */
	private Class<T> requiredType;
	
	/**
	 * 构造函数
	 * @param requiredType  需处理的类型
	 */
	public RowMapperFactory(Class<T> requiredType) {
		this.requiredType = requiredType;
	}
	
	/**
	 * 获取类型映射实例
	 * 
	 * @return  类型映射实例
	 */
	public RowMapper<T> getRowMapper(){
		if(requiredType.equals(String.class) || Number.class.isAssignableFrom(requiredType) || requiredType.equals(Date.class)){
			return new SingleColumnRowMapper<T>(requiredType);
		}else{
			return new DefaultBeanPropertyRowMapper<T>(requiredType);
		}
	}
}
